import { apiClient } from './axios';

// 分组管理相关接口
export const groupsApi = {
  // 获取分组列表
  getGroups: (params?: {
    page?: number;
    per_page?: number;
    search?: string;
    is_active?: boolean;
  }) => {
    return apiClient.get('/groups', { params });
  },

  // 获取单个分组详情
  getGroup: (groupId: number) => {
    return apiClient.get(`/groups/${groupId}`);
  },

  // 创建分组
  createGroup: (groupData: {
    name: string;
    description?: string;
    leader_id?: number;
    is_active?: boolean;
  }) => {
    return apiClient.post('/groups', groupData);
  },

  // 更新分组
  updateGroup: (groupId: number, groupData: {
    name?: string;
    description?: string;
    leader_id?: number;
    is_active?: boolean;
  }) => {
    return apiClient.put(`/groups/${groupId}`, groupData);
  },

  // 删除分组
  deleteGroup: (groupId: number) => {
    return apiClient.delete(`/groups/${groupId}`);
  },

  // 获取分组选项列表（用于下拉选择）
  getGroupOptions: () => {
    return apiClient.get('/groups/options');
  },

  // 获取分组成员
  getGroupMembers: (groupId: number) => {
    return apiClient.get(`/groups/${groupId}/members`);
  },

  // 添加分组成员
  addGroupMember: (groupId: number, userId: number) => {
    return apiClient.post(`/groups/${groupId}/members`, { user_id: userId });
  },

  // 移除分组成员
  removeGroupMember: (groupId: number, userId: number) => {
    return apiClient.delete(`/groups/${groupId}/members/${userId}`);
  },

  // 批量更新分组成员
  updateGroupMembers: (groupId: number, userIds: number[]) => {
    return apiClient.put(`/groups/${groupId}/members`, { user_ids: userIds });
  }
};